package io.litchi.auth.interfaces.facade;

import io.litchi.auth.Infrastructure.common.command.user.SaveUserCommand;
import io.litchi.auth.Infrastructure.common.command.user.UpdateUserCommand;
import io.litchi.auth.Infrastructure.common.query.user.UserListQuery;
import io.litchi.auth.Infrastructure.common.result.user.UserDetailResult;
import io.litchi.auth.Infrastructure.common.result.user.UserListResult;
import io.litchi.auth.application.service.UserService;
import io.litchi.common.page.PageCondition;
import io.litchi.common.page.PageResult;
import io.litchi.common.result.Result;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户接口
 *
 * @author helang
 * @since 2025-11-11
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@Validated
public class UserFacade {
    private final UserService userService;

    /**
     * 用户分页查询
     * @param pageCondition 条件参数
     * @return Result<List<UserListResult>>
     */
    @PostMapping("/list")
    public Result<PageResult<UserListResult>> list (@RequestBody @Valid  PageCondition<UserListQuery> pageCondition){
        return userService.list(pageCondition);
    }

    /**
     * 查询昵称是否存在
     * @param nickname 昵称
     * @return 存在返回true 不存在返回false
     */
    @GetMapping("/nicknameExist/{nickname}")
    public Result<Boolean> nicknameExist(@PathVariable String nickname){
        return userService.nicknameExist(nickname);
    }

    /**
     * 查询手机号是否存在
     * @param mobile 昵称
     * @return 存在返回true 不存在返回false
     */
    @GetMapping("/mobileExist/{mobile}")
    public Result<Boolean> mobileExist(@PathVariable String mobile){
        return userService.mobileExist(mobile);
    }

    @GetMapping("/detail/{id}")
    public Result<UserDetailResult> userDetail(@PathVariable Long id){
        return userService.userDetail(id);
    }

    @PostMapping("/save")
    public Result<Void> saveUser(@Valid @RequestBody SaveUserCommand command){
        return userService.saveUser(command);
    }

    @PostMapping("/updateStatus")
    public Result<Void> updateStatus(@Valid @RequestBody UpdateUserCommand command){
        return userService.updateStatus(command);
    }

}